package com.app.manage.moudles.push.constants;

import com.app.manage.utils.DataUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum TaskStepEnums {
    step_0(0,"草稿"),
    step_1(1,"等待执行中"),
    step_Z(-1,"任务终止"),
    step_99(99,"任务完成"),
    step_gq(999,"任务过期");

    private Integer step;

    private String name;

    public Integer getStep() {
        return step;
    }

    public void setStep(Integer step) {
        this.step = step;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    TaskStepEnums(Integer step, String name) {
        this.step = step;
        this.name = name;
    }

    public static Integer openStepOpt(Integer step){
        if(step - step_0.getStep() == 0){
            //开始
            return 0;
        }else if(step - step_1.getStep() == 0){
            //停止
            return 1;
        }else if(step - step_Z.getStep() == 0){
            //停止
            return 0;
        }else {
            return 2;
        }

    }


    /**
     * 查询可以用的步骤
     * @return
     */
    public static List<Integer>  findActSteps(){
        return Arrays.asList(step_0.getStep(),step_1.getStep());
    }

    /**
     * 查询步骤对应的名称
     * @param step
     * @return
     */
    public static String getNameByStep(Integer step){
        if(step == null){
            return "";
        }
        for (TaskStepEnums e : TaskStepEnums.values()){
            if(e.getStep() - step == 0){
                return e.getName();
            }
        }
        return null;

    }
    public static String findStep(Integer step){
        if(step == null || step < 0 || step > 100){
            return "0%";
        }

        int length = 0;
        for(TaskStepEnums e : TaskStepEnums.values()){
            if(e.getStep() <= step && e.getStep() > 0){
                length++;
            }
        }
        return DataUtils.biDiv(0,String.valueOf(length*100),"4","%");
    }


}
